<!--党员活动报名成功、我的办理列表详情-->
<template>
  <default-layout>
    <header-close :text="title" slot="header"></header-close>
    <div slot="main" class="apply-success">
      <div class="top">
        <div class="icon" :class="status === 1 ? 'icon-success' : status === 2 ? 'icon-danger' : 'icon-warning'">
          <i class="xffont xf-duigou" v-if="status === 1"></i>
          <i class="xffont xf-point" v-else-if="status === 2"></i>
          <i class="xffont xf-time" v-else></i>
        </div>
        <span class="title">{{status === 0 ? '未处理' : status === 1 ? '已通过' : '未通过'}}</span>
        <!--<span class="desc">类型：{{title}}</span>-->
      </div>
      <div class="list">
        <mt-cell is-link to="javascript:;" @click.native="look">
          <span class="left-tip" slot="icon">您可以</span>
          <span class="list-content">查看详情</span>
        </mt-cell>
        <mt-cell is-link to="javascript:;" @click.native="print" v-if="status === 1 && busiType === '4' && detail.urlPath">
          <span class="list-content">打印商调函</span>
        </mt-cell>
        <mt-cell is-link to="javascript:;" @click.native="cancel(0)" v-if="busiType === '3' && status === 0">
          <span class="list-content">撤销</span>
        </mt-cell>
        <mt-cell is-link to="javascript:;" @click.native="cancel(1)" v-if="busiType === '11' && status === 0">
          <span class="list-content">撤销</span>
        </mt-cell>
        <mt-cell is-link to="javascript:;" @click.native="cancel(2)" v-if="busiType === '6' && status === 0">
          <span class="list-content">撤销</span>
        </mt-cell>
        <mt-cell is-link to="javascript:;" @click.native="cancel(3)" v-if="busiType === '4' && status === 0">
          <span class="list-content">撤销</span>
        </mt-cell>
        <mt-cell is-link to="javascript:;" @click.native="cancel(4)" v-if="busiType === '18' && status === 0">
          <span class="list-content">撤销</span>
        </mt-cell>
        <mt-cell is-link to="javascript:;" @click.native="cancel(5)" v-if="busiType === '5' && status === 0">
          <span class="list-content">撤销</span>
        </mt-cell>
        <mt-cell is-link to="javascript:;" @click.native="cancel(6)" v-if="busiType === '8' && status === 0">
          <span class="list-content">撤销</span>
        </mt-cell>
        <mt-cell is-link to="javascript:;" @click.native="cancel(7)" v-if="busiType === '10' && status === 0">
          <span class="list-content">撤销</span>
        </mt-cell>
      </div>
    </div>
    <transition name="router">
      <router-view class="fixed-router"></router-view>
    </transition>
  </default-layout>
</template>
<script>

  import HeaderClose from '../../../components/header-close/header-close.vue'
  import DefaultLayout from '../../../layouts/default-layout/default-layout'
  import {mapGetters, mapMutations} from 'vuex'
  import {download} from '../../../common/js/util'

  export default {
    components: {DefaultLayout, HeaderClose},
    computed: {
      ...mapGetters([
        'userInfo'
      ])
    },
    data() {
      return {
        status: Number(this.$route.query.status), // 办理状态，0未处理1已通过2未通过
        title: decodeURIComponent(this.$route.query.title || ''), // 办理业务名称
        busiType: this.$route.query.busiType, // 业务类型
        detail: {} // 商调函信息
      }
    },
    methods: {
      ...mapMutations({
        setBook: 'SET_BOOK'
      }),
      look() {
        // 查看详情
        /*
          * busiType: 业务类型
          * 党员活动报名(录入后就完成，无后续动作) 2
          * 党组织关系转入(录入后就完成，无后续动作) 3
          * 申请商调函（审核通过后，下载商调函） 4
          * 档案转出（材料预审相同） 5
          * 档案借出（查询该功能对应的状态查询） 6
          * 开具证明（材料预审相同） 8
          * 省医疗保险办理 10
          * 职称申报（有审核状态，后续没有动作） 11
          * 户籍关系转入 12
          * 市养老、医疗保险办理 13
          * 养老缴费基数变更(无后续动作) 14
          * 户籍关系转出 15
          * 办理合格证明 17
          * 继续教育报名 18
          * */
        switch (String(this.busiType)) {
          case '2':
            this.$router.push(`/activities/activity?id=${this.$route.query.id}`)
            break
          case '5':
            this.lookNormal()
            break
          case '8':
            this.lookNormal()
            break
          case '12':
            this.lookNormal()
            break
          case '14':
            this.lookNormal()
            break
          case '15':
            this.lookNormal()
            break
          default:
            this.$router.push({
              name: 'myApplyDetail',
              query: this.$route.query
            })
        }
      },
      lookNormal() {
        this.setBook({
          id: this.$route.query.id,
          aac003: this.userInfo.name,
          aac002: this.userInfo.idCard,
          materialName: this.title,
          auditStatusName: this.status === 0 ? '未处理' : this.status === 1 ? '已通过' : '未通过',
          auditStatus: this.status
        })
        this.$router.push({
          name: 'myApplyDetail2',
          query: this.$route.query
        })
      },
      // 获取商调函打印信息
      getPrintInfo() {
        // 商调函信息查询
        this.$post('/admin/person/sapi/personal/records/perEntry/get/archive/letter/info', {
          cardId: this.userInfo.idCard,
          name: this.userInfo.name
        }, loading => { this.loading = loading }).then(res => {
          this.detail = res.data
        })
      },
      print() {
        // 打印商调函
        download(this.$getImg(this.detail.urlPath, {type: 'pdf'}))
      },
      cancel(type) {
        this.$message.confirm('确定撤销？').then(() => {
          switch (type) {
            case 0:
              this.cancelParty()
              break
            case 1:
              this.cancelTitle()
              break
            case 2:
              this.cancelBorrow()
              break
            case 3:
              this.cancelApply()
              break
            case 4:
              this.cancelEdu()
              break
            case 5:
              this.cancelNormal()
              break
            case 6:
              this.cancelNormal()
              break
            case 7:
              this.cancelNormal()
              break
          }
        })
      },
      cancelSuccess(res) {
        this.$message.alert(res.message).then(() => {
          this.$emit('refresh')
          this.$router.back()
        })
      },
      cancelParty() {
        // 撤销党员组织关系转入
        this.$post('/admin/person/sapi/party/organization/delete', {}, loading => { this.$message.loading(loading) }).then(res => {
          this.cancelSuccess(res)
        })
      },
      cancelTitle() {
        // 职称申报撤销
        this.$post('/admin/person/sapi/title/declaration/save/apply/delTitle', {
          titleDeclarationId: this.$route.query.id
        }, loading => { this.$message.loading(loading) }).then(res => {
          this.cancelSuccess(res)
        })
      },
      cancelBorrow() {
        // 档案借出撤销
        this.$post('/admin/person/sapi/personal/records/file/delete/loan/apply/info', {
          id: this.$route.query.id
        }, loading => { this.$message.loading(loading) }).then(res => {
          this.cancelSuccess(res)
        })
      },
      cancelApply() {
        // 撤销申请商调函
        this.$post('/admin/person/sapi/personal/records/perEntry/delete/archive/letter/info', {
          id: this.$route.query.id,
          name: this.userInfo.name,
          cardId: this.userInfo.idCard
        }, loading => { this.$message.loading(loading) }).then(res => {
          this.cancelSuccess(res)
        })
      },
      cancelEdu() {
        // 撤销继续教育
        this.$post('/admin/person/sapi/education/continuing/save/baseInfo/delConEdu', {
          id: this.$route.query.id
        }, loading => { this.$message.loading(loading) }).then(res => {
          this.cancelSuccess(res)
        })
      },
      cancelNormal() {
        // 撤销材料预审类办理
        this.$post('/sapi/preaudit/materialPreaudit/delete', {
          id: this.$route.query.id
        }).then(res => {
          this.cancelSuccess(res)
        })
      }
    },
    created() {
      if (this.status === 1 && this.busiType === '4') {
        this.getPrintInfo()
      }
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../../common/style/variable";
  .desc{
    display: inline-block;
    padding: .2rem .2rem 0 .2rem;
    text-align: center;
    line-height: .45rem;
  }
  .mint-cell{
    border-top: 1px solid #ededed;
  }
</style>
